<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>
        <span style="color: #ccc">权限列表</span></el-breadcrumb-item
      >
    </el-breadcrumb>

    <!-- 卡片视图区 -->
    <el-card class="box-card">
      <el-table :data="rightsList" stripe style="width: 100%" border>
        <el-table-column type="index" label="#" width="70"> </el-table-column>
        <el-table-column prop="authName" label="权限名称"> </el-table-column>
        <el-table-column prop="path" label="路径"> </el-table-column>
        <el-table-column prop="level" label="权限等级">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.level === '0'">一级</el-tag>
            <el-tag type="success" v-else-if="scope.row.level === '1'"
              >二级</el-tag
            >
            <el-tag type="warning" v-else>三级</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "Rights",
  data() {
    return {
      rightsList: [], // 所有的权限列表
    };
  },

  // 在每次访问权限列表前，先执行created生命周期，获取所有的权限列表数据
  created() {
    this.getRightsList();
  },

  methods: {
    //  获取权限列表
    async getRightsList() {
      // 通过axios发送数据请求，访问地址为rights/list
      const { data: res } = await this.$http.get("rights/list");
      //   console.log(res);
      if (res.meta.status !== 200) {
        return this.$message.error("获取权限列表失败");
      }

      // 成功，将得到的数据赋值给rightsList
      this.rightsList = res.data;
    },
  },
};
</script>

<style lang="less" scoped>
.el-breadcrumb {
  margin-bottom: 20px;
}

.el-card {
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15) !important;
}
</style>
